package user;

import org.apache.struts2.ServletActionContext;

import util.dao.Pagination;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private boolean isupdate=true;
	private User user=new User();
	private UserDao userDao;
	private Pagination<User> paginationUser;
	
	public boolean isIsupdate() {
		return isupdate;
	}
	public void setIsupdate(boolean isupdate) {
		this.isupdate = isupdate;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public Pagination<User> getPaginationUser() {
		return paginationUser;
	}
	public void setPaginationUser(Pagination<User> paginationUser) {
		this.paginationUser = paginationUser;
	}
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
	
	public String updateuser(){
		User temp=(User) ServletActionContext.getRequest().getSession().getAttribute("user");
		this.user=this.userDao.findById(temp.getId());
		this.isupdate=false;
		return SUCCESS;
	}
	public String showuser(){
		this.user=(User) ServletActionContext.getRequest().getSession().getAttribute("user");
		return SUCCESS;
	}
	public String showalluser(){
		if(paginationUser==null){
			paginationUser=new Pagination<User>();
		}
		if(this.paginationUser.getSize()==0){
			this.paginationUser.setSize(3);
		}
		if(this.paginationUser.getNo()<=0){
			this.paginationUser.setNo(1);
		}
		else{
			this.paginationUser.setNo(this.paginationUser.getNo());
		}
		this.userDao.browse(paginationUser);
		return SUCCESS;
	}
	public String exit(){
		ServletActionContext.getRequest().getSession().removeAttribute("user");
		return SUCCESS;
	}
	public String input(){
		return "input";
	}
	public String execute(){
		
		return SUCCESS;
	}
}
